******SET YOUR DIRECTORY to ...\replication

clear all


//////////////////////////////////////////////////////////////////////////////////////////
///Multiple places from UCR
///////////////////////////////////////////////////////////////////////////////////////////
use "intermediatedata\bridge_final.dta", clear
drop if V3==""
drop _merge

rename V3 ori

///Drop observations not inside any MSA, 418589/868611
drop if FMSA==.
///Drop observations inside MSA without city center, observation with missing: 42571/450022, observations with 0: 3532/450022
egen msawithcc=max(city_center), by(FMSA)
drop if msawithcc==0

tab FMSANAME if MULTPLC==1 & city_center==0
tab FMSANAME if MULTPLC==1 & city_center==1

gen ori_multplc_2=(MULTPLC==1)
egen ori_multplc=max(ori_multplc_2), by(FMSA)
drop ori_multplc_2

drop if FMSA==9999
collapse (mean) ori_multplc, by(FMSA)

label var ori_multplc "PD in multiple places"

keep FMSA ori_multplc

save rawdata\IntermediateData\ucr_mismeas.dta, replace

///////////////////////////////////////////////////////////////////////////////////////////
///Keep non-missing variables for CC
///////////////////////////////////////////////////////////////////////////////////////////
use "intermediatedata\data_ucr_ori.dta", clear
drop *_cty_*

///Drop observations not inside any MSA, 418589/868611
drop if FMSA==.
///Drop observations inside MSA without city center, observation with missing
egen msawithcc=max(city_center), by(FMSA)
drop if msawithcc==0

///Keep only observations of place which is city center and it is municipal jurisdiction crime
replace AGENTYPE=3 if ori=="OHCIP00" | ori=="NV00201" | ori=="INIPD00"
drop if city_center==.
drop if AGENTYPE==.
drop if city_center!=1 
drop if AGENTYPE!=3

///Keep only actual offenses
keep nonmiss* fipsplace_00 year

save rawdata\IntermediateData\ucr_nonmiss.dta, replace
 
